<style>

        .ds1{
                float: left;
        }
        #addt1{
                text-align: center;
        }
        .del1{
                font-size: 13px;
        }
        #edui2 div{
                height: 20px;
        }



        .suggestionList li {

                margin: 0px 0px 0px 0px;
                padding: 3px;
                cursor: pointer;
        }

        .suggestionList li:hover {
                background-color: #659CD8;

        }

        .all li {
                width:100px;
                height:30px;
                line-height:20px;
                text-align:center;
                float:left;
                display:inline;
                position:relative;
                cursor:pointer;
                left:-40px;
                top:-7px;
        }
        .all ul {
                position:absolute;
                left:0;
                top:30px;
                display:none;
        }
</style>

<div class="content">

    <div id="editday" class="editday">

        <div id="editt1" class="dn"></div>
        <span id="editt2" class="dn"></span>
        <div style="clear: both"></div>
        <form name="editday1" action="" method="post">
            <input type="hidden" name="p_id" value=""/>
            <input type="hidden" name="tr_id" value=""/>
            <input type="hidden" name="titlearr" value=""/>
            <button type="button" class="btn btn-success" onclick="sub()">确定修改</button>
            <a id="et1">
                <span class="stext" onclick="dtop(1,0,'','editt2')">标题文字</span>
                <span class="simg" onclick="dtop(1,0,1,'editt2')"><img src="/assets/img/new1/title/1.png" width="30"></span>
                <span class="simg" onclick="dtop(1,0,2,'editt2')"><img src="/assets/img/new1/title/2.png" width="30"></span>
                <span class="simg" onclick="dtop(1,0,3,'editt2')"><img src="/assets/img/new1/title/3.png" width="30"></span>
                <span class="simg" onclick="dtop(1,0,4,'editt2')"><img src="/assets/img/new1/title/4.png" width="30"></span>
                <span class="simg" onclick="dtop(1,0,5,'editt2')"><img src="/assets/img/new1/title/5.png" width="30"></span>
                <span class="simg" onclick="dtop(1,0,6,'editt2')"><img src="/assets/img/new1/title/6.png" width="30"></span>

            </a>
        </form>
    </div>
</div>
<script language="javascript" type="text/javascript" src="/assets/My97DatePicker/jquery-1.8.2.js"></script>
<script language="javascript" type="text/javascript" src="/assets/libs/fastadmin-layer/src/layer.js"></script>
<script language="JavaScript">

    //根据参数操作，op1--操作 1-增加 2-删除 3-修改  no1-数组下标  value1-值
    // 并根据字段输出相应input,字符串用#分割
   var  titletext="<?php echo $_REQUEST['title'];?>";

    dtsarry=titletext.split("*")
    stinput("editt2");
    //stinput("editt2");
    function dtop(op1,no1,value1,objname){

        console.log(objname+"###########");
        console.log($("#"+objname).html());
        if(op1==1){
            dtsarry[dtsarry.length]=value1;
        }
        if(op1==2){

            dtsarry[no1]=value1;
        }
        if(op1==3){
            dtsarry.splice(no1,1);
        }
        dts = dtsarry.join('*');
        //alert(dts);
        if(objname=="editt2"){
            document.editday1.titlearr.value=dts;
        }
        if(objname=="addt2"){
            document.addday1.titlearr.value=dts;
        }
       // alert(dts);
        stinput(objname)

        //$("#at1").hide();
    }

    // 根据字符串输出相应input,字符串用#分割--用于编辑

    function stinput(objname){
        var stout="";
        var objname1='"'+objname+'"';
        for(var i=0;i<dtsarry.length;i++){
            if(!isNaN(dtsarry[i])&&dtsarry[i]!=""){
                stout=stout+"<div class='ds1'><div><img width='30' src='/assets/img/new1/title/"+dtsarry[i]+".png'></div><div class='del1' onclick='dtop(3,"+i+","+1+","+objname1+")'><a href='javascript:;' class='btn btn-xs btn-danger btn-delone' data-original-title='删除'><i class='fa fa-trash'></i></a></div>"+"</div>"
            }else{
                var aa="this.value";
                //根据内容设定input宽度
                var iw=dtsarry[i].length*17
                if(iw==0){
                    iw=50;
                }
                stout=stout+"<div class='ds1'><div>" +
                    "<input style='width: "+iw+"px' onchange='dtop(2,"+i+","+aa+","+objname1+")' class='iday' type='text' value='"+dtsarry[i]+"'/>" +
                    "</div><div class='del1' onclick='dtop(3,"+i+","+1+","+objname1+")'><a href='javascript:;' class='btn btn-xs btn-danger btn-delone' data-original-title='删除'><i class='fa fa-trash'></i></a></div></div>"
            }
        }
        $("#"+objname).html(stout);

    }

    function sub(){
        var p_id="<?php echo $_REQUEST['p_id'];?>";
        var trid="<?php echo $_REQUEST['trid'];?>";
        var titlearr=$("input[name='titlearr']").val();
        $.ajax({
            type:'post',
            dataType:'json',
            url:"/admin/product/route_edit",
            data:{"p_id":p_id,"tr_id":trid,"titlearr":titlearr},
            success:function(data){
                if(data==1){
                    if(data){
                        window.parent.location.reload();
                    }else{
                        layer.alert("数据修改失败");
                    }
                }
            }
        })







    }
</script>




